package com.hanhanxiaochong.zhongxiangchuanmei.view.home.act;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.VipProjectBean;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.VipProjectItem;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseLayout;
import com.hanhanxiaochong.zhongxiangchuanmei.view.home.adapter.OnlyVipAdapter;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/4/30.
 * Desc   : 我的礼包--会员专享
 */

public class OnlyVipLayout extends BaseLayout {

    @BindView(R.id.recyclerview_vip)
    RecyclerView recyclerviewVip;
    @BindView(R.id.tv_vip_level)
    TextView tvVipLevel;

    private OnlyVipAdapter onlyVipAdapter;

    public OnlyVipLayout(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_onlyvip;
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void init() {
        String token = SharedPreferencesUtil.getsInstances(mContext).getLoginInfo().getToken();
        recyclerviewVip.setLayoutManager(new LinearLayoutManager(mContext));
        RetrofitSource.createApi(HttpPostService.class).user_vip(token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<VipProjectBean>>(this) {
                    @Override
                    public void onSuccess(ResponseBase<VipProjectBean> response) {
                        VipProjectBean data = response.getData();
                        List<VipProjectItem> list = new ArrayList<>();
                        list.addAll(data.getGrade());
                        tvVipLevel.setText(String.format(ResourcesUtils.getString(R.string.vip_level), data.getName()));
                        onlyVipAdapter = new OnlyVipAdapter(mContext, R.layout.item_onlyvip, list);
                        recyclerviewVip.setAdapter(onlyVipAdapter);
                    }
                });
    }
}
